package io;

import java.io.*;
import java.nio.charset.StandardCharsets;

/**
 * 缓冲字符流------最常用的读写字符串的流
 * 是一对高级流,并且是字符流
 * 内部维护一个默认8KB(8192)长度的char数组,还是以块读写形式读写字符以提高读写效率
 * BufferedWrite和BufferedReader
 */
public class PWDemo {
    public static void main(String[] args) throws IOException {
        //最常用写入字符串方式
        PrintWriter pw = new PrintWriter("pw.txt");
        pw.println("唯此间江湖年少偏爱纵横天下");
        pw.println("恩仇趁年华轻剑快马");
        System.out.println("写出完成");
        pw.close();
        /*
        FileOutputStream fos = new FileOutputStream("pw.txt");
        OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        BufferedWriter bw = new BufferedWriter(osw); //缓冲字符流(高级流)
        bw.write("唯此间江湖年少偏爱纵横天下,");
        bw.write("恩仇趁年华轻剑快马");
        System.out.println("写出完毕");
        bw.close(); //先调用flush()冲水
         */
    }
}
